using ASP;
using HoWave.Common;
using HoWave.Data.Bll;
using HoWave.Data.Model;
using HoWave.Web;
using HoWave.Web.Shop.Member;
using System;
using System.Data;
using System.Web.Profile;
using System.Web.SessionState;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
public class Member_Shop_PayOrder : Member, IRequiresSessionState
{
	protected Label LabOrderNum;
	protected Label LabTotalMoney;
	protected Label LbEanest;
	protected HtmlTableRow Eanest;
	protected Label LabPayedMoney;
	protected RadioButtonList PayTypeList;
	protected CheckBoxList cbl_card;
	protected TextBox ReceiptDate;
	protected TextBox TxtPoundage;
	protected HiddenField hfPoundage;
	protected Label LbrePay;
	protected TextBox Money;
	protected RangeValidator Rav1;
	protected RequiredFieldValidator Req1;
	protected TextBox Remark;
	protected CheckBox CheckSendMobileMesToCus;
	protected CheckBox CheckSendMesMesToCus;
	protected CheckBox CheckSendEmailMesToCus;
	protected Button butSubmit;
	protected Button Button2;
	public static string UserName = "";
	public static string SalerName = "";
	public static string UserTureName = "";
	public static string SalerTureName = "";
	public static int OrderFormID = 0;
	public static string OrderFormNum = "";
	public static int UserID = 0;
	public static int SalerID = 0;
	public static string Email = "";
	public static string UserEmail = "";
	public static string SalerEmail = "";
	public static int ProductID = 0;
	public bool IsBuyer = false;
	public bool IsSaler = false;
	public DataTable DTOrder;
	private string Msg = string.Empty;
	private decimal TruePayMoney = 0m;
	private decimal NotPayMoney = 0m;
	private decimal totalmoney = 0m;
	protected DefaultProfile Profile
	{
		get
		{
			return (DefaultProfile)this.Context.Profile;
		}
	}
	protected global_asax ApplicationInstance
	{
		get
		{
			return (global_asax)this.Context.ApplicationInstance;
		}
	}
	protected void Page_Load(object sender, EventArgs e)
	{
		Member_Shop_PayOrder.OrderFormNum = Fetch.Get("OrderFormNum");
		if (Member_Shop_PayOrder.OrderFormNum == string.Empty)
		{
			this.WriteErrMsg("", Language.Get("Common/LostParam", "OrderFormNum"), "");
		}
		Shop_Order shop_Order = new Shop_Order(this.conn);
		this.DTOrder = shop_Order.GetOrderByOrderFormNum(Member_Shop_PayOrder.OrderFormNum);
		DataTable dataTable = this.conn.GetDataTable("select MoneyTrue,Status from HLShop_PayInfo where OrderFormNum='" + Member_Shop_PayOrder.OrderFormNum + "'");
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			for (int i = 0; i < dataTable.Rows.Count; i++)
			{
				string a = dataTable.Rows[i]["Status"].ToString();
				if (a == "pay" || a == "NotPaySaler")
				{
					if (dataTable.Rows[i]["MoneyTrue"] != null && dataTable.Rows[i]["MoneyTrue"].ToString() != "")
					{
						this.TruePayMoney += decimal.Parse(dataTable.Rows[i]["MoneyTrue"].ToString());
					}
				}
				else
				{
					if (dataTable.Rows[i]["MoneyTrue"] != null && dataTable.Rows[i]["MoneyTrue"].ToString() != "")
					{
						this.NotPayMoney += decimal.Parse(dataTable.Rows[i]["MoneyTrue"].ToString());
					}
				}
			}
		}
		dataTable.Dispose();
		if (this.DTOrder.Rows.Count <= 0 || this.DTOrder == null || this.DTOrder.ToString() == "")
		{
			this.WriteErrMsg("", Language.Get("Common/NotData"), "");
		}
		else
		{
			if (!base.IsPostBack)
			{
				this.LabOrderNum.Text = this.DTOrder.Rows[0]["OrderFormNum"].ToString();
				this.ReceiptDate.Text = DateTime.Now.ToShortDateString();
				this.LabPayedMoney.Text = this.TruePayMoney.ToString();
				this.totalmoney = this.DTOrder.Rows[0]["MoneyTotal"].ToDecimal2();
				this.LabTotalMoney.Text = this.totalmoney.ToString();
				this.Money.Text = (this.totalmoney - this.TruePayMoney).ToString();
				if (this.ShowEanest(int.Parse(this.DTOrder.Rows[0]["ProductID"].ToString()), decimal.Parse(this.DTOrder.Rows[0]["MoneyGoods"].ToString())))
				{
					this.Eanest.Visible = true;
				}
			}
			Member_Shop_PayOrder.OrderFormID = int.Parse(this.DTOrder.Rows[0]["OrderFormID"].ToString());
			Member_Shop_PayOrder.UserID = int.Parse(this.DTOrder.Rows[0]["UserID"].ToString());
			Member_Shop_PayOrder.SalerID = int.Parse(this.DTOrder.Rows[0]["SalerID"].ToString());
			Member_Shop_PayOrder.ProductID = int.Parse(this.DTOrder.Rows[0]["ProductID"].ToString());
			Member_Shop_PayOrder.Email = this.DTOrder.Rows[0]["Email"].ToString();
			UserBll userBll = new UserBll(this.conn);
			UserInfoBll userInfoBll = new UserInfoBll(this.conn);
			DataTable userByUserID = userBll.GetUserByUserID(Member_Shop_PayOrder.UserID);
			DataTable userByUserID2 = userBll.GetUserByUserID(Member_Shop_PayOrder.SalerID);
			DataTable userInfoByUserID = userInfoBll.GetUserInfoByUserID(Member_Shop_PayOrder.UserID);
			DataTable userInfoByUserID2 = userInfoBll.GetUserInfoByUserID(Member_Shop_PayOrder.SalerID);
			Member_Shop_PayOrder.UserEmail = userByUserID.Rows[0]["Email"].ToString();
			if (userInfoByUserID2.Rows.Count > 0 && userInfoByUserID2.Rows[0]["TrueName"] != null && !string.IsNullOrEmpty(userInfoByUserID2.Rows[0]["TrueName"].ToString()))
			{
				Member_Shop_PayOrder.UserTureName = userInfoByUserID.Rows[0]["TrueName"].ToString();
			}
			else
			{
				Member_Shop_PayOrder.UserTureName = "未知";
			}
			Member_Shop_PayOrder.SalerTureName = userInfoByUserID2.Rows[0]["TrueName"].ToString();
			Member_Shop_PayOrder.UserName = userByUserID.Rows[0]["UserName"].ToString();
			Member_Shop_PayOrder.SalerName = userByUserID2.Rows[0]["UserName"].ToString();
			Member_Shop_PayOrder.SalerEmail = userByUserID2.Rows[0]["Email"].ToString();
			if (Member_Shop_PayOrder.UserID == base.user.UserID)
			{
				this.IsBuyer = true;
			}
			if (Member_Shop_PayOrder.SalerID == base.user.UserID)
			{
				this.IsSaler = true;
			}
			if (!this.IsSaler && !this.IsBuyer)
			{
				this.WriteErrMsg("", Language.Get("Common/NotData"), "");
			}
			if (!base.IsPostBack)
			{
				this.BindPayType();
				this.CountRate();
				if (this.IsSaler)
				{
					this.ReceiptDate.Enabled = true;
					this.ReceiptDate.Attributes.Add("onfocus", string.Concat(new string[]
					{
						"show_cele_date(",
						this.ReceiptDate.UniqueID,
						",'','',",
						this.ReceiptDate.UniqueID,
						");"
					}));
				}
			}
		}
	}
	public bool ShowEanest(int ProductID, decimal MoneyGoods)
	{
		decimal d = 0m;
		DataTable dataTable = this.conn.GetDataTable("select * from HLShop_Product where ProductID=" + ProductID);
		if (dataTable != null && dataTable.Rows.Count > 0)
		{
			d = Math.Round(MoneyGoods * decimal.Parse(dataTable.Rows[0]["TempSubScriptionRate"].ToString()) / 100m, 2);
		}
		this.LbEanest.Text = d.ToString();
		return d > 0m;
	}
	protected void BindPayType()
	{
		Shop_PayType shop_PayType = new Shop_PayType(this.conn);
		DataTable shousuPay = shop_PayType.GetShousuPay(Member_Shop_PayOrder.UserID);
		DataTable shousuPay2 = shop_PayType.GetShousuPay(Member_Shop_PayOrder.SalerID);
		if (this.IsBuyer)
		{
			DataTable unDisabledPayTypeByUserID = shop_PayType.GetUnDisabledPayTypeByUserID(Member_Shop_PayOrder.SalerID);
			this.PayTypeList.DataSource = unDisabledPayTypeByUserID;
			this.PayTypeList.DataBind();
			unDisabledPayTypeByUserID.Dispose();
			this.PayTypeList.SelectedValue = this.DTOrder.Rows[0]["SelectedPayType"].ToString();
			string text = base.shopconfig["PayWay"].ToString();
			if (text.Equals("0"))
			{
				this.TxtPoundage.Text = shousuPay.Rows[0]["paytip"].ToString();
				this.hfPoundage.Value = "0";
			}
			else
			{
				if (text.Equals("1"))
				{
					this.TxtPoundage.Text = "0";
					this.hfPoundage.Value = shousuPay2.Rows[0]["paytip"].ToString();
				}
				else
				{
					if (text.Equals("2"))
					{
						this.TxtPoundage.Text = shousuPay.Rows[0]["paytip"].ToString();
						this.hfPoundage.Value = shousuPay2.Rows[0]["paytip"].ToString();
					}
				}
			}
		}
		else
		{
			if (this.IsSaler)
			{
				this.hfPoundage.Value = shousuPay2.Rows[0]["paytip"].ToString();
				this.PayTypeList.Items.Clear();
				this.PayTypeList.DataSource = shop_PayType.GetOffLinePayTypeByUserID(Member_Shop_PayOrder.SalerID);
				this.PayTypeList.DataBind();
				if (this.PayTypeList.Items.Count > 0)
				{
					this.PayTypeList.Items[0].Selected = true;
				}
				else
				{
					this.butSubmit.Enabled = false;
				}
			}
		}
	}
	protected void CountRate()
	{
		string selectedValue = this.PayTypeList.SelectedValue;
		if (!string.IsNullOrEmpty(selectedValue))
		{
			if (selectedValue.Trim() != "0")
			{
				this.TxtPoundage.Text = "0";
				this.hfPoundage.Value = "0";
			}
		}
	}
	protected void Button1_Click(object sender, EventArgs e)
	{
		decimal num = this.Money.Text.ToDecimal2();
		string text = this.Remark.Text;
		if (num <= 0m)
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Order/PayOrder/PayMoneyErr", new string[0]), "");
		}
		if (text != string.Empty)
		{
			if (text.Length > 300)
			{
				this.WriteErrMsg("", Language.Get("Common/TooLong"), "");
			}
		}
		int num2 = 0;
		try
		{
			num2 = Convert.ToInt32(this.PayTypeList.SelectedValue);
		}
		catch
		{
			this.WriteErrMsg("", Language.GetMemberMsg("Order/PayOrder/NotSelectPayType", new string[0]), "");
		}
		decimal d = this.LabTotalMoney.Text.ToDecimal2() - this.LabPayedMoney.Text.ToDecimal2();
		decimal d2 = num;
		bool flag = false;
		bool ifFirstTime = false;
		if (this.DTOrder.Rows[0]["TradeType"].IsNull(new object[0]) == "2" || this.DTOrder.Rows[0]["TradeType"].IsNull(new object[0]) == "3")
		{
			if (this.DTOrder.Rows[0]["MoneyReceipt"].ToDecimal2() == 0m)
			{
				ifFirstTime = true;
				DataTable dataTable = this.conn.GetDataTable("Select TempSubScriptionRate From [HLShop_Product] Where ProductID=" + this.DTOrder.Rows[0]["ProductID"]);
				if (dataTable.Rows.Count > 0)
				{
					if (dataTable.Rows[0]["TempSubScriptionRate"].ToDecimal2() > 0m)
					{
						if (num < dataTable.Rows[0]["TempSubScriptionRate"].ToDecimal2() * this.DTOrder.Rows[0]["MoneyGoods"].ToDecimal2() / 100m)
						{
							this.WriteErrMsg("", Language.GetMemberMsg("Order/PayOrder/FirstSubscriptionNotEnough", new string[0]), "");
						}
						flag = true;
					}
				}
			}
		}
		if (this.IsBuyer)
		{
			string sql = string.Concat(new string[]
			{
				"UPDATE [HLShop_Order] SET [SelectedPayType] =",
				this.PayTypeList.SelectedValue,
				" WHERE OrderFormNum='",
				this.LabOrderNum.Text,
				"'"
			});
			this.conn.Execute(sql);
			if (d2 > d)
			{
				this.WriteErrMsg("", Language.GetMemberMsg("Order/PayOrder/PayToMuch", new string[0]), "");
			}
			decimal num3 = this.TxtPoundage.Text.ToDecimal2() * num / 100m;
			decimal mustfee = this.hfPoundage.Value.ToDecimal2() * num / 100m;
			OrderAction orderAction = new OrderAction(this.conn);
			if (num2 == 0)
			{
				if (base.user.Balance < num + num3)
				{
					this.WriteErrMsg("", Language.GetMemberMsg("Order/PayOrder/NotBalance", new string[0]), "");
				}
				if (orderAction.ShopBankPayOrder(Member_Shop_PayOrder.UserID, Member_Shop_PayOrder.OrderFormID, num, text, num3, true, base.shopconfig["PayWay"].ToString(), mustfee))
				{
					if (flag)
					{
						if (this.DTOrder.Rows[0]["TradeType"].IsNull(new object[0]) == "2")
						{
						}
					}
					this.Msg += Language.GetMemberMsg("Order/PayOrder/PaySuccess", new string[0]);
					this.SendMsg();
				}
				else
				{
					this.WriteErrMsg("", Language.Get("Common/Fail", ""), "");
				}
				this.AfterPayment(orderAction, ifFirstTime);
			}
			else
			{
				if (num2 > 0)
				{
					Shop_PayType shop_PayType = new Shop_PayType(this.conn);
					DataTable unDisabledPayTypeByUserID = shop_PayType.GetUnDisabledPayTypeByUserID(Member_Shop_PayOrder.SalerID);
					if (unDisabledPayTypeByUserID.Rows.Count <= 0)
					{
						this.WriteErrMsg("", Language.Get("Common/NotData"), "");
					}
					else
					{
						DataTable payTypeByUserIDTypeID = shop_PayType.GetPayTypeByUserIDTypeID(Member_Shop_PayOrder.SalerID, num2);
						bool flag2 = payTypeByUserIDTypeID.Rows[0]["PayType"].ToString().Equals("2");
						payTypeByUserIDTypeID.Dispose();
						if (!flag2)
						{
							string productPath = this.config["SiteUrl"].ToString() + "ShowProduct.aspx?ProductID={0}";
							orderAction.PayOrderOnline(Member_Shop_PayOrder.UserID, Member_Shop_PayOrder.OrderFormNum, Member_Shop_PayOrder.OrderFormID, num2, num, text, productPath, flag2);
						}
						else
						{
							orderAction.OffLinePayOrder(Member_Shop_PayOrder.OrderFormID, Member_Shop_PayOrder.UserID, num, DateTime.Now, num2, text);
							base.Response.Redirect("Shop_PayMents.aspx");
						}
						base.Response.End();
					}
				}
			}
		}
		else
		{
			if (this.IsSaler)
			{
				if (num2 < 0)
				{
					this.WriteErrMsg("", Language.Get("Common/Fail", ""), "");
				}
				DateTime dateTime = DateTime.Now;
				try
				{
					dateTime = Convert.ToDateTime(this.ReceiptDate.Text);
				}
				catch
				{
					this.WriteErrMsg("", Language.Get("Common/DateTimeFormatErr", ""), "");
				}
				OrderAction orderAction2 = new OrderAction(this.conn);
				if (flag)
				{
					if (this.DTOrder.Rows[0]["TradeType"].ToString() == "2")
					{
					}
				}
				this.conn.Execute("update HLShop_PayInfo set Status='pay' where OrderFormNum='" + Member_Shop_PayOrder.OrderFormNum + "'");
				this.Msg += Language.Get("Common/Success");
				this.SendMsg();
			}
		}
		this.WriteSuccessMsg("", this.Msg, "Shop_BuyOrder.aspx?OrderFormNum=" + Member_Shop_PayOrder.OrderFormNum);
	}
	private void EditInfoItem()
	{
		if (Member_Shop_PayOrder.OrderFormID > 0)
		{
			Shop_Order shop_Order = new Shop_Order();
			DataTable orderAreadyByOrderID = shop_Order.GetOrderAreadyByOrderID(Member_Shop_PayOrder.OrderFormID);
			for (int i = 0; i < orderAreadyByOrderID.Rows.Count; i++)
			{
				string value = "";
				if (orderAreadyByOrderID.Rows[i]["PayTime"] != DBNull.Value)
				{
					value = orderAreadyByOrderID.Rows[i]["PayTime"].IsNull(new object[0]);
				}
				decimal d = 0m;
				if (orderAreadyByOrderID.Rows[i]["MoneyTotal"] != DBNull.Value)
				{
					d = orderAreadyByOrderID.Rows[i]["MoneyTotal"].ToDecimal2();
				}
				decimal num = 0m;
				if (orderAreadyByOrderID.Rows[i]["MoneyReceipt"] != DBNull.Value)
				{
					num = orderAreadyByOrderID.Rows[i]["MoneyReceipt"].ToDecimal2();
				}
				decimal num2 = 0m;
				if (orderAreadyByOrderID.Rows[i]["alMoneyReceipt"] != DBNull.Value)
				{
					decimal d2 = orderAreadyByOrderID.Rows[i]["alMoneyReceipt"].ToDecimal2();
					if (num > d2)
					{
						num2 = num - d2;
					}
				}
				decimal value2 = d + num2;
				DataTable dataTable = BLLInstance.BllStockInfoOrder.GetList("OrderID=" + Member_Shop_PayOrder.OrderFormID).Tables[0];
				for (int j = 0; j < dataTable.Rows.Count; j++)
				{
					int infoOrderID = dataTable.Rows[j]["InfoOrderID"].ToInt32(new int[0]);
					HoWave.Data.Model.StockInfoOrder model = BLLInstance.BllStockInfoOrder.GetModel(infoOrderID);
					if (model != null)
					{
						model.InfoOrderID = infoOrderID;
						model.Fee = new decimal?(num2);
						if (!string.IsNullOrEmpty(value))
						{
							model.ReceiptDate = new DateTime?(Convert.ToDateTime(value));
						}
						model.ReceiptMoney = new decimal?(value2);
						model.AlreadyReceiptMoney = new decimal?(num);
						BLLInstance.BllStockInfoOrder.Update(model);
					}
				}
			}
		}
	}
	protected void SendMsg()
	{
		string text = "支付提醒";
		string text2;
		string sender;
		string mailTo;
		string text3;
		if (this.IsSaler)
		{
			text2 = Member_Shop_PayOrder.UserName;
			sender = Member_Shop_PayOrder.SalerName;
			mailTo = Member_Shop_PayOrder.UserEmail;
			text3 = this.config["MessageOfReceiveMoney"].ToString();
		}
		else
		{
			text2 = Member_Shop_PayOrder.SalerName;
			sender = Member_Shop_PayOrder.UserName;
			mailTo = Member_Shop_PayOrder.SalerEmail;
			text3 = this.config["MessageOfPayMoney"].ToString();
		}
		text3 = text3.Replace("{$UserName$}", text2);
		text3 = text3.Replace("{$InputTime$}", DateTime.Now.ToString());
		text3 = text3.Replace("{$OrderFormNum$}", Member_Shop_PayOrder.OrderFormNum);
		if (this.CheckSendMesMesToCus.Checked)
		{
			MessageBll messageBll = new MessageBll(this.conn);
			if (messageBll.AddMessage(sender, "Users", text, text3, 0, 0, 1, 0, text2, "", 1))
			{
				this.Msg = this.Msg + "<br/>" + Language.GetMemberMsg("Order/Notice/MessageSuccess", new string[0]);
			}
		}
		if (this.CheckSendEmailMesToCus.Checked)
		{
			string text4 = this.config["SiteName"].ToString();
			string smtpserver = this.config["MailSmtpServer"].ToString();
			string mailuser = this.config["MailServerUserName"].ToString();
			string mailpassword = this.config["MailServerPassWord"].ToString();
			string mailFrom = this.config["MailServerFrom"].ToString();
			Email email = new Email();
			if (email.SendEmail(smtpserver, mailuser, mailpassword, mailFrom, text3, mailTo, text))
			{
				this.Msg = this.Msg + "<br/>" + Language.GetMemberMsg("Order/Notice/EmailSuccess", new string[0]);
			}
		}
		if (this.CheckSendMobileMesToCus.Checked)
		{
			if (this.DTOrder.Rows[0]["Mobile"] != null)
			{
				string text5 = this.DTOrder.Rows[0]["Mobile"].ToString();
				if (text5 == "" || text5 == null)
				{
					this.Page.ClientScript.RegisterStartupScript(base.GetType(), "Test", "<script>alert('手机号不存在,无法发送!');</script>");
				}
				else
				{
					MobileMessage mobileMessage = new MobileMessage();
					if (mobileMessage.Send(text5, text3, text2))
					{
						this.Msg = this.Msg + "<br/>" + Language.GetMemberMsg("Order/Notice/MobileSuccess", new string[0]);
					}
				}
			}
		}
	}
	private void CheckLead()
	{
		decimal num = Convert.ToDecimal(this.DTOrder.Rows[0]["AuctionEndPrice"]);
		DataTable dataTable = this.conn.GetDataTable("Select CurrentPrice,ImcrementPrice From [HLShop_Product] Where ProductID in(select top 1 ProductID From [HLShop_OrderItem] Where OrderFormID=" + Member_Shop_PayOrder.OrderFormID + ")");
		decimal num2 = Convert.ToDecimal(dataTable.Rows[0]["CurrentPrice"]);
		decimal d = Convert.ToDecimal(dataTable.Rows[0]["ImcrementPrice"]);
		decimal num3 = num2;
		int num4 = 0;
		Shop_Order shop_Order = new Shop_Order(this.conn);
		DataTable maxAuctionPriceByProductID = shop_Order.GetMaxAuctionPriceByProductID(Convert.ToInt32(this.DTOrder.Rows[0]["ProductID"]), Convert.ToInt32(this.DTOrder.Rows[0]["Cycle"]), Convert.ToDecimal(dataTable.Rows[0]["TempSubScriptionRate"]) == 0m);
		if (maxAuctionPriceByProductID.Rows.Count > 0)
		{
			num4 = Convert.ToInt32(maxAuctionPriceByProductID.Rows[0]["OrderFormID"]);
			num3 = Convert.ToDecimal(maxAuctionPriceByProductID.Rows[0]["AuctionEndPrice"]);
		}
		if (num > num3)
		{
			num2 = num3 + d;
			if (shop_Order.SetOrderLead(Member_Shop_PayOrder.OrderFormID, num2))
			{
				if (num4 > 0)
				{
					if (num3 > Convert.ToDecimal(maxAuctionPriceByProductID.Rows[0]["MoneyGoods"]))
					{
						shop_Order.AddAuctionOrderByAgent(num3, num4, 0);
					}
				}
			}
		}
		else
		{
			if (num < num3)
			{
				if (num > Convert.ToDecimal(this.DTOrder.Rows[0]["MoneyGoods"]))
				{
					shop_Order.AddAuctionOrderByAgent(num, Member_Shop_PayOrder.OrderFormID, 0);
				}
				num2 = num + d;
				shop_Order.AddAuctionOrderByAgent(num2, num4, 1);
			}
			else
			{
				if (num == num3)
				{
					this.conn.Execute("Update [HLShop_Order] Set Status=0 Where OrderFormID=" + Member_Shop_PayOrder.OrderFormID);
					if (num > Convert.ToDecimal(this.DTOrder.Rows[0]["MoneyGoods"]))
					{
						shop_Order.AddAuctionOrderByAgent(num, Member_Shop_PayOrder.OrderFormID, 0);
					}
					shop_Order.AddAuctionOrderByAgent(num, num4, 1);
				}
			}
		}
	}
	public void AfterPayment(OrderAction accdeta, bool IfFirstTime)
	{
		decimal num = 0m;
		int teamNum = 0;
		if (this.DTOrder.Rows[0]["TradeType"].ToString() == "3")
		{
			DataTable dataTable = this.conn.GetDataTable("select Cycle from HLShop_Order where OrderFormNum='" + Member_Shop_PayOrder.OrderFormNum + "'");
			int num2 = int.Parse(dataTable.Rows[0]["Cycle"].ToString());
			dataTable.Dispose();
			DataTable dataTable2 = this.conn.GetDataTable("select * from HLShop_Product where ProductID=" + Member_Shop_PayOrder.ProductID);
			if (dataTable2 != null && dataTable2.Rows.Count > 0)
			{
				num = decimal.Parse(dataTable2.Rows[0]["TempSubScriptionRate"].ToString());
				teamNum = int.Parse(dataTable2.Rows[0]["TeamNum"].ToString());
			}
			dataTable2.Dispose();
			if (num > 0m && IfFirstTime)
			{
				int buyLeavel = 0;
				DataTable dataTable3 = this.conn.GetDataTable(string.Concat(new object[]
				{
					"select TeamLeaVel from HLUser_RecordTeam where ProductID=",
					Member_Shop_PayOrder.ProductID,
					" and UserID=",
					Member_Shop_PayOrder.UserID
				}));
				if (dataTable3 != null && dataTable3.Rows.Count > 0)
				{
					buyLeavel = int.Parse(dataTable3.Rows[0]["TeamLeavel"].ToString());
				}
				accdeta.ProcessingTeamData(Member_Shop_PayOrder.UserID, Member_Shop_PayOrder.ProductID, buyLeavel, teamNum);
				accdeta.UpdataTeamRemembereffectOrder(Member_Shop_PayOrder.ProductID, num2);
				if (accdeta.JustPaysMoneyAndquantity(Member_Shop_PayOrder.ProductID, num2, num))
				{
					this.conn.Execute(string.Concat(new object[]
					{
						"Update HLShop_Order set Cycle=",
						num2,
						"+1 where Cycle=",
						num2,
						" and MoneyReceipt<=0"
					}));
					this.conn.Execute(string.Concat(new object[]
					{
						"Update HLShop_Order set Teameffect=1,Remembereffect=0 where MoneyReceipt>0 and Cycle=",
						num2,
						" and OrderFormID in (select OrderFormID from HLShop_OrderItem where ProductID=",
						Member_Shop_PayOrder.ProductID,
						")"
					}));
					accdeta.ClearRecord(Member_Shop_PayOrder.ProductID, num2);
				}
			}
		}
	}
}
